/*
 * Project: Daycare Web Application
 * Package: com.made2ordersoftware.daycare.domain
 * File:    ChildProfileEntity.java
 * Created: Dec 20, 2010
 */
/**
 * Copyright (c) 2010 Made 2 Order Software, LLC
 *
 * All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 * transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 * You may not distribute the URL or redistribute the files to third parties. You may transfer the files onto
 * a single storage device so long as you can prove ownership of the software. You may not reverse engineer,
 * decompile, or disassemble the software or media files. You may not modify or translate the software or
 * media, or distribute copies of the software or media without the written consent of Made 2 Order Software,
 * LLC.
 */
package com.made2ordersoftware.daycare.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.made2ordersoftware.daycare.domain.enums.Gender;
import com.made2ordersoftware.util.StringUtility;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Entity class representing the detailed information of a child registered with the day care.
 *
 * @author David Canning <dcannin@gmail.com>
 * @version 1.0.0
 */
@Entity
@Table(name = "child_profile")
@XmlRootElement
public class ChildProfileEntity implements Serializable {

    private static final Logger LOG = LoggerFactory.getLogger(ChildProfileEntity.class);
    private static final long serialVersionUID = 1L;
    @Id
    private Long id;
    @Basic(optional = false)
    @Column(name = "birth_date")
    @Temporal(TemporalType.DATE)
    private Date birthDate;
    private String nickname;
    private String comments;
    @Basic(optional = false)
    @Enumerated(EnumType.STRING)
    private Gender gender;
    @MapsId
    @JoinColumn(name = "id", referencedColumnName = "id")
    @OneToOne(optional = false)
    private ChildEntity child;

    /**
     * Creates an instance of <code>ChildProfileEntity</code>.
     */
    public ChildProfileEntity() {
    }

    /**
     * Creates an instance of <code>ChildProfileEntity</code>.
     *
     * @param birthDate Child's birth date
     * @param gender    Child's gender
     */
    public ChildProfileEntity(Date birthDate, Gender gender) {
        this.birthDate = birthDate;
        this.gender = gender;
    }

    /**
     * Returns the id of the ChildProfile.
     *
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets the id of this ChildProfile.
     *
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Returns the birth date of the ChildProfile.
     *
     * @return the birthDate
     */
    public Date getBirthDate() {
        return (Date) birthDate.clone();
    }

    /**
     * Sets the birth date of this ChildProfile.
     *
     * @param birthDate
     */
    public void setBirthDate(Date birthDate) {
        this.birthDate = new Date(birthDate.getTime());
    }

    /**
     * Returns the nickname of the ChildProfile.
     *
     * @return the nickName
     */
    public String getNickname() {
        return nickname;
    }

    /**
     * Sets the nickname of this ChildProfile.
     *
     * @param nickname
     */
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    /**
     * Returns the comments of the ChildProfile.
     *
     * @return comments
     */
    public String getComments() {
        return comments;
    }

    /**
     * Sets the comments of the ChildProfile.
     *
     * @param comments
     */
    public void setComments(String comments) {
        this.comments = comments;
    }

    /**
     * @return the gender
     */
    public Gender getGender() {
        return gender;
    }

    /**
     * @param gender the gender to set
     */
    public void setGender(Gender gender) {
        this.gender = gender;
    }

    /**
     * Returns the Child associated with this ChildProfile.
     *
     * @return the child
     */
    public ChildEntity getChild() {
        return child;
    }

    /**
     * Sets the Child associated with this ChildProfile.
     *
     * @param child
     */
    public void setChild(ChildEntity child) {
        this.child = child;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 71 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof ChildProfileEntity)) {
            return false;
        }
        ChildProfileEntity other = (ChildProfileEntity) object;
        return Objects.equals(this.id, other.getId());
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("\nChileProfileEntity{ id=").append(
                StringUtility.ifNotNullToString(getId()));
        sb.append("\n\tNick name=").append(this.nickname);
        sb.append("\n\tBirth date=").append(this.birthDate);
        sb.append("\n\tComments=").append(this.comments);
        sb.append("\n\tGender=").append(this.gender);
        sb.append("}");
        return sb.toString();
    }

}
